package com.fimmlps.reronge.controller;

import com.fimmlps.reronge.utils.OssUtils;
import com.fimmlps.reronge.vo.TResponseVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
public class FileController {

    //POST 上传图片到OSS，并返回图片存储的url
    @PostMapping("/upload")
    public TResponseVo<String> upload(@RequestParam("uploadFile") MultipartFile uploadFile){
        try {
            String url = OssUtils.upload(uploadFile.getOriginalFilename(),uploadFile.getInputStream());
            return TResponseVo.success(url);
        } catch (Exception e){

            return TResponseVo.error(500,e.getMessage());
        }
    }
}
